﻿// -----------------------------------------------------------------------
// <copyright file="SubscriberPrimaryKey.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Subscription
{
	/// <summary>
	/// Represents the primary key of a subscriber consisting of its
	/// application id and its subscriber id. 
	/// </summary>
	public class SubscriberPrimaryKey
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="SubscriberPrimaryKey"/> class.
		/// </summary>
		/// <param name="pushApplicationId">The push application id.</param>
		/// <param name="subscriberId">The subscriber id.</param>
		public SubscriberPrimaryKey(string pushApplicationId, string subscriberId)
		{
			PushApplicationId = pushApplicationId;
			SubscriberId = subscriberId;
		}

		/// <summary>
		/// Gets the push application id.
		/// </summary>
		/// <value>The push application id.</value>
		public string PushApplicationId
		{
			get;
			private set;
		}

		/// <summary>
		/// Gets the subscriber id.
		/// </summary>
		/// <value>The subscriber id.</value>
		public string SubscriberId
		{
			get;
			private set;
		}

		/// <summary>
		/// Returns a hash code for this instance.
		/// </summary>
		/// <returns>
		/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
		/// </returns>
		public override int GetHashCode()
		{
			return (PushApplicationId.GetHashCode() << 5) ^ SubscriberId.GetHashCode();
		}

		/// <summary>
		/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
		/// </summary>
		/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
		/// <returns>
		/// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
		/// </returns>
		public override bool Equals(object obj)
		{
			SubscriberPrimaryKey rhs = obj as SubscriberPrimaryKey;
			if(rhs == null)
			{
				return false;
			}
			return PushApplicationId == rhs.PushApplicationId && SubscriberId == rhs.SubscriberId;
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return string.Format("SubscriberPrimaryKey[App:{0}, Sub:{1}]",
				PushApplicationId, SubscriberId);
		}
	}
}
